package main

import "fmt"

func containsNearbyDuplicate(nums []int, k int) bool {
	maps := make(map[int]int)
	for index, num := range nums {
		if existIndex, ok := maps[num]; ok && index-existIndex <= k {
			return true
		}
		maps[num] = index
	}
	return false
}

func main() {
	fmt.Println(containsNearbyDuplicate([]int{1, 2, 3, 1, 2, 3}, 2))
	fmt.Println(containsNearbyDuplicate([]int{1, 2, 3, 1}, 3))
}
